package questionLibrary;
/**
 * Class QuestionInfo is used to store information about question and about possible answers on it.
 * 
 * @version 1.37 11 jun 2012
 * @author Anton Samarsky
 * @author Vladimir Vyshko
 */
public class QuestionInfo {
	
	private String question;
	
	private String[] answer;
	
	private OrganInfo[] organEffect;
	
	
	/**
	 * This method writes a text of the question to inner string.
	 * @param _question is question that will copy to inner string.
	 */
	public void insertQuestion(String question) {
		this.question = question;
	}
	
	/**
	 * This method writes a text of all possible answers.
	 * @param _answer is array of string, each of which is possible answer.
	 */
	public void insertAnswers(String...answers) {
		
		answer = answers;
		organEffect = new OrganInfo[answer.length];
		for (int i = 0; i < organEffect.length; i++)
			organEffect[i] = new OrganInfo();
	}
	
	/**
	 * This method writes effects of every answer on chosen organ.
	 * Warning! Count of answers can be less then count of bonuses in params bonus.
	 * @param organ is organ, which will get effects of answers.
	 * @param param is parameter of organ, which will be changed (for example, energy of brain).
	 * @param bonus is number of points (with sign + or -), which characterize some positive or negative effect (0 is neutral effect).
	 * @throws IllegalArgumentException if it was specified nonexistent organ.
	 */
	public void insertEffects(int organ, int param, int...bonus) {
		 
		if (param > SomeConstants.COUNT_OF_PARAMS || param < 0)
			throw new IllegalArgumentException("It was specified wrong parameter!");
		if (answer.length != bonus.length)
			throw new IllegalArgumentException("Wrong count of arguments! Count of effects must be equal count of answers.");
		
		for (int numberOfAnswer = 0; numberOfAnswer < answer.length; numberOfAnswer++){
			
			organEffect[numberOfAnswer].setParameter(organ, param, bonus[numberOfAnswer]);
		}
	}
	
	/**
	 * This method is used for getting text of question.
	 * @return text of question.
	 */
	public String getQuestion() {
		return this.question; //TODO check this!
		//XXX
	}
	
	/**
	 * This method is used for getting text of answers.
	 * @return text of answers.
	 */
	public String[] getAnswers() {
		return answer.clone();
	}
	
	/**
	 * This method returns effect for some parameter param for organ organ. 
	 * @param organ is organ, which will get effects of answers.
	 * @param param is parameter of organ, which will be changed (for example, energy of brain).
	 * @param answer_number is number of answers which affects on some effect of some organ.
	 * @throws IllegalArgumentException if it was specified nonexistent organ.
	 * @throws IndexOutOfBoundsException if some answer_number is less than zero or greater then bigest answer's number.  
	 * @return summary effect of all answers for some param of some organ.
	 */
	public int getEffect(int organ, int param, int...answerNumber) {
		if (organ > SomeConstants.COUNT_OF_ORGANS || organ < 0)
			throw new IllegalArgumentException("It was specified wrong organ!");
		int result = 0; 
		for (int numberOfAnswer:answerNumber){
			result += organEffect[numberOfAnswer].getParameter(organ, param);
		}
		return result;
	}
	
	/**
	 * This simple method returns count of answers, which was specified in constructor.
	 * @return count of answers.
	 */
	public int getCountOfAnswers() {
		return answer.length;
	}
}